package com.smart.upms.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.core.starter.utils.CopyUtils;
import com.smart.upms.sys.entity.SysOauthClientDetails;
import com.smart.upms.sys.mapper.SysOauthClientDetailsMapper;
import com.smart.upms.sys.param.SysOauthClientDetailsParam;
import com.smart.upms.sys.param.SysOauthClientDetailsQueryParam;
import com.smart.upms.sys.result.SysOauthClientDetailsResult;
import com.smart.upms.sys.service.ISysOauthClientDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author guxiaobai
 * @since 2018-12-05
 */
@Service
@AllArgsConstructor
public class SysOauthClientDetailsServiceImpl implements ISysOauthClientDetailsService {

    private final SysOauthClientDetailsMapper mapper;


    @Override
    public Boolean save(SysOauthClientDetailsParam param) {
        SysOauthClientDetails entity = CopyUtils.copyObject(param, SysOauthClientDetails.class);
        int insert = mapper.insert(entity);
        return insert > 0;
    }

    @Override
    public Boolean update(SysOauthClientDetailsParam param) {
        SysOauthClientDetails entity = CopyUtils.copyObject(param, SysOauthClientDetails.class);
        int update = mapper.updateById(entity);
        return update > 0;

    }

    @Override
    public Boolean delete(String id) {
        int delete = mapper.deleteById(id);
        return delete > 0;
    }

    @Override
    public SysOauthClientDetailsResult get(String id) {
        SysOauthClientDetails entity = mapper.selectById(id);
        return CopyUtils.copyObject(entity, SysOauthClientDetailsResult.class);
    }

    @Override
    public List<SysOauthClientDetailsResult> list(SysOauthClientDetailsQueryParam param) {
        QueryWrapper<SysOauthClientDetails> queryWrapper = new QueryWrapper<>();
        List<SysOauthClientDetails> entityList = mapper.selectList(queryWrapper);
        return CopyUtils.copyList(entityList, SysOauthClientDetailsResult.class);
    }

    @Override
    public Page<SysOauthClientDetailsResult> listPage(Page<SysOauthClientDetailsResult> page, SysOauthClientDetailsQueryParam param) {
        QueryWrapper<SysOauthClientDetails> queryWrapper = new QueryWrapper<>();
        Page<SysOauthClientDetails> entityPage = new Page<>();
        entityPage.setSize(page.getSize());
        entityPage.setCurrent(page.getCurrent());
        entityPage.setAsc(page.ascs());
        entityPage.setDesc(page.descs());
        mapper.selectPage(entityPage, queryWrapper);
        Page<SysOauthClientDetailsResult> resultPage = CopyUtils.copyPage(entityPage, SysOauthClientDetailsResult.class);
        return resultPage;
    }


}
